effect = "MD",
control = list(adapt_delta = 0.999, max_treedepth = 15))
# Summarize the effects for other methodologies
effects_summary_other <- data.frame(summary(fit_other$fit, pars = c("theta_k"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary_other$Author <- fit_other$data$Author
# Add Average Effects (mu and tau)
over_all_other <- data.frame(summary(fit_other$fit, pars = c("mu"), prob = c(0.025,0.05,0.95,0.975))$summary)
# Label the types for clarity
over_all_exog$type <- "Exogenous eligibility"
over_all_other$type <- "Other methodologies"
# Combine results into a single dataframe
df_methodology <- bind_rows(over_all_exog, over_all_other)
rownames(df_methodology) <- NULL
# Graph methodology:--------------------
png(
filename = file.path(path, "Outputs/Employment/figA7_Methodology.png"),
width = 6,   # Width in inches
height = 4,  # Height in inches
units = "in",  # Units (inches)
res = 600      # Resolution (dots per inch)
)
ggplot(df_methodology, aes(x = mean, y = type)) +
geom_point(size = 3, color = "#4682B4") +
geom_errorbarh(aes(xmin = X2.5., xmax = X97.5.), height = 0.2, color = "#4682B4", linewidth = 1) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", linewidth = 1) +
geom_text(aes(label = sprintf("%.1f", mean)), vjust = -1.5, size = 5, color = "black") +
labs(title = "", x = "Effect Size", y = "") +
scale_x_continuous(
limits = c(min(df_methodology$X2.5.), max(df_methodology$X97.5.)),
breaks = sort(unique(c(seq(floor(min(df_methodology$X2.5.)),
ceiling(max(df_methodology$X97.5.)),
by = 10), 0)))) +  # <- Paréntesis extra aquí
theme_classic() +
theme(
legend.position = "none",
plot.margin = margin(l = 20, r = 20, t = 10, b = 10),
axis.text.y = element_text(size = 17),
axis.text.x = element_text(size = 14),
axis.title.x = element_text(size = 14, margin = margin(t = 10))
)
# Close the graphics device (after creating the plot)
dev.off()
View(df_methodology)
ggplot(df_methodology, aes(x = mean, y = type)) +
geom_point(size = 3, color = "#4682B4") +
geom_errorbarh(aes(xmin = X2.5., xmax = X97.5.), height = 0.2, color = "#4682B4", linewidth = 1) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", linewidth = 1) +
geom_text(aes(label = sprintf("%.1f", mean)), vjust = -1.5, size = 5, color = "black") +
labs(title = "", x = "Effect Size", y = "") +
scale_x_continuous(
limits = c(min(df_methodology$X2.5.), max(df_methodology$X97.5.)),
breaks = sort(unique(c(seq(floor(min(df_methodology$X2.5.)),
ceiling(max(df_methodology$X97.5.)),
by = 10), -1)))) +  # <- Paréntesis extra aquí
theme_classic() +
theme(
legend.position = "none",
plot.margin = margin(l = 20, r = 20, t = 10, b = 10),
axis.text.y = element_text(size = 17),
axis.text.x = element_text(size = 14),
axis.title.x = element_text(size = 14, margin = margin(t = 10))
)
ggplot(df_methodology, aes(x = mean, y = type)) +
geom_point(size = 3, color = "#4682B4") +
geom_errorbarh(aes(xmin = X2.5., xmax = X97.5.), height = 0.2, color = "#4682B4", linewidth = 1) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", linewidth = 1) +
geom_text(aes(label = sprintf("%.1f", mean)), vjust = -1.5, size = 5, color = "black") +
labs(title = "", x = "Effect Size", y = "") +
scale_x_continuous(
limits = c(-1, max(df_methodology$X97.5.)),
breaks = sort(unique(c(seq(floor(min(df_methodology$X2.5.)),
ceiling(max(df_methodology$X97.5.)),
by = 10), -1)))) +  # <- Paréntesis extra aquí
theme_classic() +
theme(
legend.position = "none",
plot.margin = margin(l = 20, r = 20, t = 10, b = 10),
axis.text.y = element_text(size = 17),
axis.text.x = element_text(size = 14),
axis.title.x = element_text(size = 14, margin = margin(t = 10))
)
# Close the graphics device (after creating the plot)
dev.off()
png(
filename = file.path(path, "Outputs/Employment/figA7_Methodology.png"),
width = 6,   # Width in inches
height = 4,  # Height in inches
units = "in",  # Units (inches)
res = 600      # Resolution (dots per inch)
)
ggplot(df_methodology, aes(x = mean, y = type)) +
geom_point(size = 3, color = "#4682B4") +
geom_errorbarh(aes(xmin = X2.5., xmax = X97.5.), height = 0.2, color = "#4682B4", linewidth = 1) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", linewidth = 1) +
geom_text(aes(label = sprintf("%.1f", mean)), vjust = -1.5, size = 5, color = "black") +
labs(title = "", x = "Effect Size", y = "") +
scale_x_continuous(
limits = c(-1, max(df_methodology$X97.5.)),
breaks = sort(unique(c(seq(floor(min(df_methodology$X2.5.)),
ceiling(max(df_methodology$X97.5.)),
by = 10), -1)))) +  # <- Paréntesis extra aquí
theme_classic() +
theme(
legend.position = "none",
plot.margin = margin(l = 20, r = 20, t = 10, b = 10),
axis.text.y = element_text(size = 17),
axis.text.x = element_text(size = 14),
axis.title.x = element_text(size = 14, margin = margin(t = 10))
)
# Close the graphics device (after creating the plot)
dev.off()
png(
filename = file.path(path, "Outputs/Employment/figA7_Methodology.png"),
width = 6,   # Width in inches
height = 4,  # Height in inches
units = "in",  # Units (inches)
res = 600      # Resolution (dots per inch)
)
ggplot(df_methodology, aes(x = mean, y = type)) +
geom_point(size = 3, color = "#4682B4") +
geom_errorbarh(aes(xmin = X2.5., xmax = X97.5.), height = 0.2, color = "#4682B4", linewidth = 1) +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", linewidth = 1) +
geom_text(aes(label = sprintf("%.1f", mean)), vjust = -1.5, size = 5, color = "black") +
labs(title = "", x = "Effect Size", y = "") +
scale_x_continuous(
limits = c(-1, max(df_methodology$X97.5.)),
breaks = sort(unique(c(seq(floor(min(df_methodology$X2.5.)),
ceiling(max(df_methodology$X97.5.)),
by = 10), 0)))) +  # <- Paréntesis extra aquí
theme_classic() +
theme(
legend.position = "none",
plot.margin = margin(l = 20, r = 20, t = 10, b = 10),
axis.text.y = element_text(size = 17),
axis.text.x = element_text(size = 14),
axis.title.x = element_text(size = 14, margin = margin(t = 10))
)
# Close the graphics device (after creating the plot)
dev.off()
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
write_xlsx(data_table, file.path(path, "Outputs/Employment/Tab_2_Meta_Regression.xlsx"))
write.xlsx(PD$data, file.path(path, "Outputs/Employment/Employment_predictive_distribution.xlsx"))
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.2 Data Analysis -Sales.R"),  echo = TRUE)
source(file.path(path, "Code/02.3 Data Analysis -Profit.R"),  echo = TRUE)
## 1.6 Methodology_Type: Exogenous Eligibility vs Other ---------
table(df_employment$Methodology_Type)
# Filter data for exogenous eligibility
df_employment_exog <- df_employment %>%
filter(Methodology_Type == "Exogenous eligibility")
# Fit the model for exogenous eligibility using baggr
set.seed(426)
fit_exog <- baggr(df_employment_exog,
model = "rubin",
pooling = "partial",
prior_hypermean = normal(0, 100),
prior_hypersd = normal(0, 100),
iter = 5000,
warmup = 3000,
effect = "MD",
control = list(adapt_delta = 0.999, max_treedepth = 15))
# Summarize the effects for exogenous eligibility
effects_summary_exog <- data.frame(summary(fit_exog$fit, pars = c("theta_k"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary_exog$Author <- fit_exog$data$Author
# Add Average Effects (mu and tau)
over_all_exog <- data.frame(summary(fit_exog$fit, pars = c("mu"), prob = c(0.025,0.05,0.95,0.975))$summary)
# Filter data by methodology
df_employment_other <- df_employment %>%
filter(Methodology_Type == "Other methodology")
# Fit the model for other methodology using baggr
set.seed(426)
fit_other <- baggr(df_employment_other,
model = "rubin",
pooling = "partial",
prior_hypermean = normal(0, 100),
prior_hypersd = normal(0, 100),
iter = 5000,
warmup = 3000,
effect = "MD",
control = list(adapt_delta = 0.999, max_treedepth = 15))
# Summarize the effects for other methodologies
effects_summary_other <- data.frame(summary(fit_other$fit, pars = c("theta_k"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary_other$Author <- fit_other$data$Author
# Add Average Effects (mu and tau)
over_all_other <- data.frame(summary(fit_other$fit, pars = c("mu"), prob = c(0.025,0.05,0.95,0.975))$summary)
# Label the types for clarity
over_all_exog$type <- "Exogenous eligibility"
over_all_other$type <- "Other methodologies"
# Combine results into a single dataframe
df_methodology <- bind_rows(over_all_exog, over_all_other)
rownames(df_methodology) <- NULL
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
print(path)
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
df_employment<-read_excel(file.path(path, "Data/Intermediate/df_employment.xlsx"))
str(df_employment)
set.seed(426)
fit <- baggr(df_employment, model = "rubin", pooling = "partial",
prior_hypermean = normal(0, 100),
prior_hypersd = normal(0, 100),  # Usar normal para la SD
iter = 5000, warmup = 3500,
effect = "MD", control = list(adapt_delta = 0.99, max_treedepth = 15))
effects_summary <- data.frame(summary(fit$fit, pars = c("theta_k"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary$Author<-fit$data$Author
effects_summary$Region<-fit$data$Region
effects_summary$Income_group<-fit$data$Income_group
effects_summary<-effects_summary %>% arrange(-mean)
over_all<-data.frame(summary(fit$fit, pars = c("mu"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary<-bind_rows(effects_summary,over_all)
effects_summary$Author[nrow(effects_summary)] <- "Average Effect"
#Generate excel file with BHM Estimates
write_xlsx(effects_summary, file.path(path, "Outputs/Employment/BHM_Employment.xlsx"))
write_xlsx(meta_summary_REML, file.path(path, "Outputs/Employment/REML_Employment.xlsx"))
## BAYESIAN ESTIMATION
# Baggr (Rachael Meager, Witold Wiecek)--------------------
df_employment<-read_excel(file.path(path, "Data/Intermediate/df_employment.xlsx"))
str(df_employment)
set.seed(426)
fit <- baggr(df_employment, model = "rubin", pooling = "partial",
prior_hypermean = normal(0, 100),
prior_hypersd = half_normal(100),  # Usar normal para la SD
iter = 5000, warmup = 3500,
effect = "MD", control = list(adapt_delta = 0.99, max_treedepth = 15))
help("baggr")
write_xlsx(meta_summary_REML, file.path(path, "Outputs/Employment/REML_Employment.xlsx"))
## BAYESIAN ESTIMATION
# Baggr (Rachael Meager, Witold Wiecek)--------------------
df_employment<-read_excel(file.path(path, "Data/Intermediate/df_employment.xlsx"))
str(df_employment)
set.seed(426)
fit <- baggr(df_employment, model = "rubin", pooling = "partial",
prior_hypermean = normal(0, 50),
prior_hypersd = normal(0, 100),  # Usar normal para la SD
iter = 5000, warmup = 3500,
effect = "MD", control = list(adapt_delta = 0.99, max_treedepth = 15))
effects_summary <- data.frame(summary(fit$fit, pars = c("theta_k"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary$Author<-fit$data$Author
effects_summary$Region<-fit$data$Region
effects_summary$Income_group<-fit$data$Income_group
effects_summary<-effects_summary %>% arrange(-mean)
over_all<-data.frame(summary(fit$fit, pars = c("mu"), prob = c(0.025,0.05,0.95,0.975))$summary)
effects_summary<-bind_rows(effects_summary,over_all)
effects_summary$Author[nrow(effects_summary)] <- "Average Effect"
#Generate excel file with BHM Estimates
write_xlsx(effects_summary, file.path(path, "Outputs/Employment/BHM_Employment.xlsx"))
#### Do Formal Loans Boost SME Performance? Key Takeaways from a Meta-Analysis ####
#### Main R Script #####
rm(list = ls()) # Remove all objects from the environment
options(scipen = 999)
# This line is to start the timer
start_time <- Sys.time() #Start time
# Load libraries ----
# Install the required packages
required_packages <- c("tidyverse", "meta", "readxl", "ggplot2", "tidyr", "writexl", "baggr", "stargazer","rstan","openxlsx","forestplot", "ggpubr","xtable")
# Install any package that is not already installed
for (pkg in required_packages) {
if (!requireNamespace(pkg, quietly = TRUE)) {
install.packages(pkg)
}
}
# Load the libraries
library(tidyverse)   # For data manipulation and visualization (includes dplyr, ggplot2, tidyr, etc.)
library(meta)        # For conducting meta-analyses
library(readxl)      # For reading Excel files (.xlsx)
library(ggplot2)     # For creating plots and visualizations
library(tidyr)       # For reshaping and tidying data
library(writexl)     # For writing data frames to Excel files (.xlsx)
library(baggr)       # For Bayesian meta-analysis
library(stargazer)   # For creating formatted tables (e.g., regression output) for LaTeX, HTML, or text
library(rstan)       # For Bayesian modeling using Stan
library(openxlsx)    # For reading, writing, and editing Excel files without Java dependency
library(forestplot)  # For forest plot
library(ggpubr)      # For ggarrange plots
library(xtable)      # For creating latex tables from dataframes
# Set package path ----
# This is the root directory where files are stored.
# For replication purposes, please replace this path with the location where you saved the "Reproducibility Package" folder.
path <- "C:/Users/wb317778/OneDrive - WBG/Current/SME Finance Lab/Reproducibility Package/"
# Run the R scripts ----
# Source the scripts that are part of your project.
source(file.path(path, "Code/01-processing-data.R"))
source(file.path(path, "Code/02.1-Data Analysis -Employment.R"),  echo = TRUE)
source(file.path(path, "Code/02.2 Data Analysis -Sales.R"),  echo = TRUE)
source(file.path(path, "Code/02.3 Data Analysis -Profit.R"),  echo = TRUE)
## This line is to end the timer
end_time <- Sys.time() # End time
# Calculate execution time in minutes and seconds
execution_time <- as.numeric(difftime(end_time, start_time, units = "secs"))
minutes <- floor(execution_time / 60)
seconds <- round(execution_time %% 60)
# Print execution time in minutes and seconds
print(paste("Execution time:", minutes, "minutes and", seconds, "seconds"))
